<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <script src="socket.io.js"></script>
</head>
<body>
  <textarea id="content"></textarea>
</body>
<script>
    var socket = io.connect('http://localhost:8000');
    //监听welcome事件，接收欢迎消息
    socket.on('welcome',function(data){
      console.log(data);
    })
    //监听STC事件，接收别的好友发的消息
    socket.on('STC',function(data){
      console.log('接收：'+data);
    })
    var content = document.querySelector("#content");
    content.onkeyup=function(e){
      if(e.keyCode==13){
        //触发CTS事件，将文本框的值发送给服务器
        socket.emit('CTS',this.value);
        this.value="";
      }
    }
</script>
</html>